<template>
  <el-card class="box-card" v-loading="loading">
    <el-button type="primary" size="small" @click="add">添加</el-button>
    <el-button size="small">default</el-button>
    <el-button type="success" size="small">success</el-button>
    <el-button type="warning" size="small">warning</el-button>
    <el-button type="danger" size="small">danger</el-button>
    <el-button type="info" size="small">info</el-button>
    <el-table
      class="table-contnet"
      style="width: 100%"
      :border="true"
      :data="tableData"
    >
      <el-table-column type="index" label="序号" width="70" :align="'center'" />
      <el-table-column
        prop="name"
        label="名称"
        :align="'center'"
        show-overflow-tooltip
      />
      <el-table-column
        prop="date"
        label="日期"
        :align="'center'"
        show-overflow-tooltip
      />
      <el-table-column
        prop="city"
        label="城市"
        :align="'center'"
        show-overflow-tooltip
      />
      <el-table-column
        prop="address"
        label="地址"
        :align="'center'"
        show-overflow-tooltip
      />
      <el-table-column
        prop="desc"
        label="描述"
        :align="'center'"
        show-overflow-tooltip
      />
    </el-table>
    <el-pagination
      v-model:current-page="pageNum"
      v-model:page-size="pageSize"
      :page-sizes="[3, 5, 10, 20, 50]"
      :size="'small'"
      :disabled="disabled"
      :background="background"
      layout="prev, pager, next, jumper, ->, sizes, total"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <!-- 新增弹框 -->
    <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      v-model="dialogFormVisible"
      title="新增数据"
      width="500"
    >
      <el-form ref="addFormRef" :model="addForm" :label-width="50">
        <el-form-item label="名称" prop="name">
          <el-input v-model="addForm.name" autocomplete="off" />
        </el-form-item>
        <el-form-item label="日期" prop="date">
          <el-input v-model="addForm.date" autocomplete="off" />
        </el-form-item>
        <el-form-item label="城市" prop="city">
          <el-input v-model="addForm.city" autocomplete="off" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="addForm.address" autocomplete="off" />
        </el-form-item>
        <el-form-item label="描述" prop="desc">
          <el-input v-model="addForm.desc" autocomplete="off" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button size="small" @click="cancel">取消</el-button>
          <el-button size="small" type="primary" @click="submit">确定</el-button>
        </div>
      </template>
    </el-dialog>
  </el-card>
</template>

<script lang="ts" setup>
import { onMounted, ref, reactive } from 'vue'
import { reqHasTrademark } from '@/api/product/trademark'
import type {
  Records,
  TradeMarkResponseData,
} from '@/api/product/trademark/type'
import type { TradeMark } from '@/api/product/trademark/type'

// 加载动画
const loading = ref(false)
// 表格数据
let tableData = ref<Records>([])

// 分页相关
const pageNum = ref<number>(1)
const pageSize = ref<number>(3)
const background = ref(false)
const disabled = ref(false)
const total = ref<number>(0)

const addFormRef = ref(null)
// 新增表单
const addForm = reactive<TradeMark>({
  name: '',
  date: '',
  city: '',
  address: '',
  desc: '',
})

onMounted(() => {
  getHasTrademark()
})

const handleSizeChange = (val: number) => {
  pageSize.value = val
  getHasTrademark()
}
const handleCurrentChange = (val: number) => {
  pageNum.value = val
  getHasTrademark()
}

// 新增弹框
const dialogFormVisible = ref(false)

// 查询接口
const getHasTrademark = async () => {
  loading.value = true
  let result: TradeMarkResponseData = await reqHasTrademark(
    pageNum.value,
    pageSize.value,
  )
  tableData.value = result.data.records
  total.value = result.data.total
  pageNum.value = result.data.pageNum
  pageSize.value = result.data.pageSize
  setTimeout(() => {
    loading.value = false
  }, 1000)
}

// 新增按钮
const add = () => {
  dialogFormVisible.value = true
}

// 取消弹框
const cancel = () => {
  dialogFormVisible.value = false
  addFormRef.value.resetFields()
}

// 提交新增
const submit = () => {}
</script>

<style lang="scss" scoped>
.box-card {
  .table-contnet {
    margin: 20px 0px;
  }
}
</style>
